package org.sith.gwt;

import java.util.jar.*;
import java.util.*;
import java.io.*;

public class PackageUtils {


    private static final String CLASS_EXT = ".class";

    public static List<String> getClasseNamesInPackage
            (String jarName, String packageName) throws IOException {
        List<String> classes = new ArrayList<String>();


        packageName = packageName.replaceAll("\\.", "/");


            JarInputStream jarFile = new JarInputStream
                    (new FileInputStream(jarName));
            JarEntry jarEntry;

            while ((jarEntry = jarFile.getNextJarEntry())!=null) {

                if ((jarEntry.getName().startsWith(packageName)) &&
                        (jarEntry.getName().endsWith(CLASS_EXT))) {
                    String clazzPathEntry = jarEntry.getName().replaceAll("/", "\\.");
                    clazzPathEntry = clazzPathEntry.replace(CLASS_EXT, "");
                    classes.add(clazzPathEntry);
                }
            }

        return classes;
    }
}
